

/**
 * Report request time of system
 * @module report
 * @since 1.0.0
 */
module.exports = (options, app) => {

    return async (ctx, next) => {

        console.log("====================================")
        console.log( ctx.request )
        // request start time
        const start = Date.parse(new Date());
    	console.log( ctx.session );
    	//console.log( "origin: ", ctx.request.origin );
    	//console.log( "host  : ", ctx.request.host );
    	//console.log( "URL   : ", ctx.request.URL );
    	//console.log( "ctx.request.header.referer: ", ctx.request.header.referer );
    	var user = ctx.session.user;
        console.log( "session user :", user );

    	if( !user && ctx.request.url != '/api/v1/login'){
            console.log( user ,  ctx.request.url );
    		console.log( ' not login get/post , invalid user forbidden' );
    		ctx.response.status = 403;
    		ctx.response.body = { error:"forbidden"};
    		return ;
    	}

        await next();

        // reqeust time spent
        const interval = Date.parse(new Date()) - start;
        console.log( ctx.response.status )
        console.log("===========", interval, "===============")
    }
}
